<template>
    <div>

    </div>
</template>

<script>
    import list from '@m/mixins/list'

    export default {
        name: 'CourseList',
        mixins: [list],
        data() {
            return {
                api: this.$api.course.list,
            }
        },
        computed: {
            filter() {
                return {
                    ...this.$root.dict
                }
            },
            postIds() {
                if (this.$root.userInfo) {
                    return this.$root.userInfo.postIds
                } else {
                    return []
                }
            },
            dataList() {
                return this.list.map(item => {
                    item.courseTimeList.sort((a, b) => {
                        if (this.postIds.includes(6)) {
                            return a.fxsPrice - b.fxsPrice
                        }
                        return a.sellamount - b.sellamount
                    })
                    // 正常价格
                    item.normalMoney = item.courseTimeList[0] ? item.courseTimeList[0].sellamount : 0
                    if (this.postIds.includes(6)) {
                        // 分销商价格
                        item.money = item.courseTimeList[0] ? item.courseTimeList[0].fxsPrice : 0
                    } else {
                        item.money = item.normalMoney
                    }
                    return item
                })
            }
        },
        async mounted() {
            this.handlerSearch()
        },
        components: {
            RadioGroup,
            Radio
        },
        methods: {
            handlerSort(item, index) {
                this.searchForm.seqtype = item.type
                if (this.search.seqtype === item.type) {
                    if (item.seque === 'asc') {
                        item.seque = 'desc'
                        this.searchForm.seque = 'desc'
                    } else {
                        item.seque = 'asc'
                        this.searchForm.seque = 'asc'
                    }
                }
                this.sort.list.splice(index, 1, item)
                this.handlerSearch()
            },
            handlerToggleFilterBox(e) {
                this.filterBox.show = !this.filterBox.show
                // document.querySelector('#app').scrollTop = e.target.getBoundingClientRect().top + e.target.scrollTop
            },
            handlerFilterTab(v, key) {
                let arr = this.searchForm[key]
                let ind = arr.indexOf(v.dictCode)
                if (ind > -1) {
                    arr.splice(ind, 1)
                } else {
                    arr.push(v.dictCode)
                }
            },
            handlerClearFormFilter() {
                this.searchForm.cprice = []
                this.searchForm.ctype = []
                this.searchForm.cday = []
                this.searchForm.cage = []
                this.searchForm.cname = ''
                this.handlerStartFilter()
            },
            handlerStartFilter() {
                let sobj = JSON.parse(JSON.stringify(this.searchForm))
                for (let i in sobj) {
                    if (Array.isArray(sobj[i])) {
                        sobj[i] = sobj[i].join()
                    }
                }
                this.search = sobj
                this.filterBox.show = false
                this.handlerSearch()
            }
        }
    }
</script>

<style lang="scss">
    @import "./style";
</style>
